package com.jc.auth.domain.service.impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import com.alibaba.fastjson.JSON;
import com.jc.auth.common.enums.AuthUserStatusEnum;
import com.jc.auth.common.enums.IsDeletedFlagEnum;
import com.jc.auth.domain.convert.AuthRoleBOConverter;
import com.jc.auth.domain.convert.AuthUserBOConverter;
import com.jc.auth.domain.entity.AuthRoleBO;
import com.jc.auth.domain.service.AuthRoleDomainService;
import com.jc.auth.infra.basic.entity.AuthRole;
import com.jc.auth.infra.basic.entity.AuthUser;
import com.jc.auth.infra.basic.mapper.AuthRoleDao;
import com.jc.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: ASL_ly
 * @Package: com.jc.auth.domain.service.impl
 * @Project: jc-club
 * @Date: 2024/10/29  11:22
 */
@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource
    private AuthRoleService authRoleService;

    /**
     * 新增角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("roleController.add.bo:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOToRole(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.code);
        Integer count = authRoleService.insert(authRole);
        return count > 0;
    }

    /**
     * 修改角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("roleController.update.bo:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOToRole(authRoleBO);
        Integer count = authRoleService.update(authRole);
        return count > 0;
    }

    /**
     * 删除角色
     * @param authRoleBO
     * @return
     */
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("roleController.delete.bo:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOToRole(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.code);
        Integer count = authRoleService.update(authRole);
        return count > 0;
    }
}
